package com.benyi.byiee.start;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.benyi.byiee"})
public class WebApplication extends SpringBootServletInitializer {
	
	public static class CustomGenerator implements BeanNameGenerator {
        @Override
        public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
            return definition.getBeanClassName();
        }
    }
	
	public static void main(String[] args) {
	    //SpringApplication.run(SpringWebStartApplication.class, args);
		SpringApplicationBuilder b = new SpringApplicationBuilder(WebApplication.class);
		b = b.beanNameGenerator(new CustomGenerator());
		b.run(args);
	}
	 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // 注意这里要指向原先用main方法执行的Application启动类
        return builder.sources(WebApplication.class);
    }
}